using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace FlashWP
{
    [Guid("859a6d18-dcc2-430f-9873-f414d49839a4")]
    public class FlashWP : System.Web.UI.WebControls.WebParts.WebPart
    {
        public FlashWP()
        {
            
        }
        private int flashWidth = 300;
        private int flashHeight = 200;
        private string flashUrl;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Width"),
        WebDescription("Width of the flash")]
        public int FlashWidth
        {
            get { return flashWidth; }
            set { flashWidth = value; }
        }


        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Height"),
        WebDescription("Height of the flash")]
        public int FlashHeight
        {
            get { return flashHeight; }
            set { flashHeight = value; }
        }


        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("URL"),
        WebDescription("Url of the flash file")]
        public string FlashUrl
        {
            get { return flashUrl; }
            set { flashUrl = value; }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!String.IsNullOrEmpty(FlashUrl))
            {
                StringBuilder _outstring = new StringBuilder();

                _outstring.Append("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
                 _outstring.Append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" "); 
                 _outstring.Append("WIDTH="); 
                 _outstring.Append(flashWidth.ToString() );
                 _outstring.Append(" HEIGHT=" );
                 _outstring.Append(flashHeight.ToString());
                 _outstring.Append("> " );
                 _outstring.Append("<PARAM NAME=movie VALUE=\""); 
                 _outstring.Append(flashUrl );
                 _outstring.Append("\"> " );
                 _outstring.Append("<PARAM NAME=WMODE VALUE=\"Transparent\">"); 
                 _outstring.Append("<PARAM NAME=quality VALUE=high> " );
                 _outstring.Append("<EMBED src=\"" );
                 _outstring.Append(flashUrl );
                 _outstring.Append("\" quality=high wmode=\"transparent\" WIDTH=\""); 
                 _outstring.Append(flashWidth.ToString() );
                 _outstring.Append("\" HEIGHT=\"" );
                 _outstring.Append(flashHeight.ToString() );
                 _outstring.Append("\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED> "); 
                 _outstring.Append("</OBJECT>");
                writer.Write(_outstring.ToString());
            }
            else
            {
                writer.Write("Modify Webpart to add content URL");
            }
        }
    }
}
